﻿using AutoMapper;
using Domain.User;
using Infratructure.Interface;
using MediatR;
using MES.Server.API.Application.Command.Production_Modules.PurchaseOrder;
using MES.Server.API.Dto.Warehouse;
using ReturnValue;

namespace MES.Server.API.Application.Handler.Production_Modules.PurchaseOrder
{
    public class GetVendorHander : IRequestHandler<GetVendorCommand, ApiPaging<GetVendorOutPut>>
    {
        private readonly IRepository<VendorModel> vendorRepo;
        private readonly IMapper mapper;
        public GetVendorHander(IRepository<VendorModel> vendorRepo, IMapper mapper)
        {
            this.vendorRepo = vendorRepo;
            this.mapper = mapper;
        }
        /// <summary>
        /// 供应商下拉
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiPaging<GetVendorOutPut>> Handle(GetVendorCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiPaging<GetVendorOutPut>();
            var vendor = vendorRepo.GetAll().Where(x => x.IsDel == false);
            var zhi = mapper.Map<List<GetVendorOutPut>>(vendor);
            result.TotalPage = zhi.ToList();
            result.Totalcount = zhi.Count();
            result.Code = StatusCode.Success;
            return Task.FromResult(result);
        }
    }
}
